/**
 * 所有版权归 广西梧州 陈锦韬 所有
 *
 * @Title: MyAuthenticationSuccessHandler
 * @Package com.rx.bean
 * @Description: 成功返回
 * @author: 陈锦韬
 * @date: 2020\5\22 0022
 * @version V1.0
 * @Copyright: 2020 陈锦韬  All rights reserved.
 */
package com.rx.core.bean;

import cn.hutool.core.codec.Base64;
import com.alibaba.fastjson.JSON;
import com.rx.core.base.RxBaseConstant;
import com.rx.core.base.RxResponse;
import lombok.extern.slf4j.Slf4j;
import org.springframework.security.authentication.BadCredentialsException;
import org.springframework.security.core.Authentication;
import org.springframework.security.web.authentication.SavedRequestAwareAuthenticationSuccessHandler;
import org.springframework.stereotype.Component;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @author: Administrator
 * @Description: 成功返回
 * @date: 2020\5\22 0022
 */
@Component
@Slf4j
public class RxSuccessHandler extends SavedRequestAwareAuthenticationSuccessHandler {

    @Override
    public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response, Authentication authentication) throws IOException, ServletException {
        log.info("登录成功");
        response.setContentType(RxBaseConstant.APPLICATION_JSON_UTF8_VALUE);
        RxResponse ok = RxResponse.ok();
        ok.setResultMessage("登录成功");
        response.getWriter().write(JSON.toJSONString(ok));
    }

}
